import http from '@/utils/http'

const BASE_URL = '/task/testLog'

export interface TestLogResp {
  id: string
  startTime: string
  endTime: string
  testHour: string
  overtimeHour: string
  registerStatus: string
  testDescription: string
  isFault: string
  faultDescription: string
  name: string
  taskId: string
  createUserString: string
  updateUserString: string
}
export interface TestLogDetailResp {
  id: string
  startTime: string
  endTime: string
  testHour: string
  overtimeHour: string
  registerStatus: string
  testDescription: string
  isFault: string
  faultDescription: string
  name: string
  taskId: string
  createUser: string
  createTime: string
  updateUser: string
  updateTime: string
  createUserString: string
  updateUserString: string
}
export interface TestLogQuery {
  startTime: string
  endTime: string
  testHour: string
  overtimeHour: string
  registerStatus: string
  isFault: string
  name: string
  sort: Array<string>
}
export interface TestLogPageQuery extends TestLogQuery, PageQuery {}

/** @desc 查询试验工作量列表 */
export function listTestLog(query: TestLogPageQuery) {
  return http.get<PageRes<TestLogResp[]>>(`${BASE_URL}`, query)
}

/** @desc 查询试验工作量详情 */
export function getTestLog(id: string) {
  return http.get<TestLogDetailResp>(`${BASE_URL}/${id}`)
}

/** @desc 新增试验工作量 */
export function addTestLog(data: any) {
  return http.post(`${BASE_URL}`, data)
}

/** @desc 修改试验工作量 */
export function updateTestLog(data: any, id: string) {
  return http.put(`${BASE_URL}/${id}`, data)
}

/** @desc 删除试验工作量 */
export function deleteTestLog(id: string) {
  return http.del(`${BASE_URL}/${id}`)
}

/** @desc 导出试验工作量 */
export function exportTestLog(query: TestLogQuery) {
  return http.download<any>(`${BASE_URL}/export`, query)
}

export interface DeviceDataStatisticReq {
  startTime: string
  endTime: string
  deviceId: string
}

/** @desc 根据设备ID查询数据统计 */
export function dataStatisticByDeviceId(dataStatisticReq: DeviceDataStatisticReq) {
  return http.post<any>(`${BASE_URL}/dataStatisticByDeviceId`, dataStatisticReq)
}

export interface ProjectDataStatisticReq {
  startTime: string
  endTime: string
  projectId: string
}

/** @desc 根据项目ID查询数据统计 */
export function dataStatisticByProjectId(dataStatisticReq: ProjectDataStatisticReq) {
  return http.post<any>(`${BASE_URL}/dataStatisticByProjectId`, dataStatisticReq)
}

export interface UserDataStatisticReq {
  startTime: string
  endTime: string
  userId: string
}

/** @desc 根据人员ID查询数据统计 */
export function dataStatisticByUserId(dataStatisticReq: UserDataStatisticReq) {
  return http.post<any>(`${BASE_URL}/dataStatisticByUserId`, dataStatisticReq)
}

export interface BaseDataStatisticReq {
  startTime: string
  endTime: string
}

/** @desc 查询试验准备统计 */
export function dataStatisticForPrepare(dataStatisticReq: BaseDataStatisticReq) {
  return http.post<any>(`${BASE_URL}/dataStatisticForPrepare`, dataStatisticReq)
}

export interface DataStatisticResp {
  totalTestHours: string
  overtimeHours: string
  workDays: number
}
export interface DailyTestStatisticResp {
  date: string
  testHours: number
  preparationHours: number
}

export interface TestStatisticQueryReq {
  projectId: string
  taskId?: string
  startDate: string
  endDate: string
}

/** @desc 获取每日试验统计数据 */
export function getDailyTestStatistics(query: TestStatisticQueryReq) {
  return http.get<DailyTestStatisticResp[]>(`${BASE_URL}/statistics`, query)
}
export interface ProjectDurationItem {
  projectName: string
  duration: number
}

export interface ProjectDurationResp {
  items: ProjectDurationItem[]
  totalDuration: number
}

/** @desc 获取项目试验时长统计 */
export function getProjectDurationStats(params: {
  startDate: string;
  endDate: string
}) {
  return http.get<ProjectDurationResp>(`${BASE_URL}/projectDurationStats`, params)
}

